Skip to content

fix: Weave-Clickhouse - #325

Open
collinol wants to merge 12 commits into
mainfrom
fix/Weave-Clickhouse
Open

fix: Weave-Clickhouse#325
collinol wants to merge 12 commits into
mainfrom
fix/Weave-Clickhouse

Conversation

@collinol

@collinol collinol commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • ClickHouse status now reports whether replication is enabled and includes the managed cluster name.
    • External ClickHouse configurations support replication and cluster name settings.
    • Status schemas expose replication and cluster name fields.
    • Legacy configuration conversion recognizes ClickHouse replication settings with clear precedence handling.
  • Bug Fixes

    • External ClickHouse status preserves declared replication and cluster details.
  • Tests

    • Added coverage for replication conversion and status reporting.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ec71770-e5ca-4683-b3dc-8b1a462ec79e

📥 Commits

Reviewing files that changed from the base of the PR and between 1f68cb1 and fffe81c.

📒 Files selected for processing (1)
  • api/v2/weightsandbiases_types.go
💤 Files with no reviewable changes (1)
  • api/v2/weightsandbiases_types.go

📝 Walkthrough

Walkthrough

ClickHouse connections now carry optional replication and cluster-name metadata. v1 conversion resolves these values from environment and structured settings. Managed and external status publication preserves the metadata, with updated CRD schemas and tests.

Changes

ClickHouse replication topology

Layer / File(s) Summary
Replication conversion mapping
api/v1/weightsandbiases_conversion_mapping.go, api/v1/weightsandbiases_conversion_overrides.go
v1 conversion maps replication and cluster values to external ClickHouse configuration, resolves precedence, rejects conflicts, and removes topology variables from legacy overrides.
Connection contract and CRD schemas
api/v2/weightsandbiases_types.go, config/crd/bases/..., internal/crdinstaller/crds/operator/...
The ClickHouse connection contract and CRD schemas define optional replicated and clusterName fields.
ClickHouse status inference
internal/controller/infra/managed/clickhouse/altinity/naming.go, internal/controller/reconciler/clickhouse.go
Managed status derives replication from replica count and publishes the Altinity CHI cluster name. External status preserves declared values.
Conversion and status validation
api/v1/*replication_test.go, internal/controller/infra/managed/clickhouse/altinity/naming_test.go, internal/controller/reconciler/clickhouse_replication_test.go
Tests cover mapping precedence, conflicts, defaults, annotation preservation, and managed and external status publication.

Estimated code review effort: 4 (Complex) | ~45 minutes

Mergeability Score: ⚪ Minimal · up to fffe8

The PR is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant V1Values
  participant Conversion
  participant ClickHouseConnection
  participant Reconciler
  participant ClickHouseStatus
  V1Values->>Conversion: Read replication and cluster values
  Conversion->>ClickHouseConnection: Set replicated and clusterName
  Reconciler->>ClickHouseConnection: Read managed or external connection
  Reconciler->>ClickHouseStatus: Publish connection metadata
Loading

Possibly related PRs

Suggested reviewers: danielpanzella

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title references ClickHouse but does not describe the primary change: replication and cluster-name support. Update the title to describe ClickHouse replication and cluster-name support.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/Weave-Clickhouse

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@collinol
collinol marked this pull request as ready for review August 11, 2026 16:26
@collinol
collinol requested a review from a team as a code owner August 11, 2026 16:26

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
internal/controller/reconciler/clickhouse_replication_test.go (1)

33-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the restating helper comment.

Lines 33-34 only describe what inferManagedClickHouseStatus does. The function name already provides that information.

Proposed fix
-// inferManagedClickHouseStatus runs the managed status path and returns the
-// published ClickHouse status for the default instance.
 func inferManagedClickHouseStatus(t *testing.T, replicas int32) apiv2.ClickHouseInfraStatus {

As per coding guidelines, “Do not add inline comments that merely restate what code does; comments should concisely explain why.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/controller/reconciler/clickhouse_replication_test.go` around lines
33 - 34, Remove the redundant comment immediately preceding
inferManagedClickHouseStatus, leaving the function implementation unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/v2/weightsandbiases_types.go`:
- Line 837: Change Replicated from bool to *bool so managed single-replica
ClickHouse preserves false while external ClickHouse leaves it nil; update
managed ClickHouse construction to set the pointer and regenerate deepcopy and
CRD artifacts. Add JSON coverage verifying false, true, and omitted values.

In `@internal/controller/reconciler/clickhouse_replication_test.go`:
- Line 1: Rename the pull request title from “fix/Weave-Clickhouse” to a
Conventional Commit format using an allowed type and an uppercase subject, such
as “fix: Weave ClickHouse”.
- Around line 1-13: Convert the tests in clickhouse_replication_test.go from
testing.T functions to the existing Ginkgo suite configured by suite_test.go,
removing the direct testing import. Register the cases with Ginkgo and replace
testing.T assertions with Gomega matchers, preserving the existing test behavior
and envtest setup.

---

Nitpick comments:
In `@internal/controller/reconciler/clickhouse_replication_test.go`:
- Around line 33-34: Remove the redundant comment immediately preceding
inferManagedClickHouseStatus, leaving the function implementation unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6ffcde3b-130a-42cd-971a-4f76192dd742

📥 Commits

Reviewing files that changed from the base of the PR and between 97e2635 and 43550f7.

📒 Files selected for processing (7)
  • api/v2/weightsandbiases_types.go
  • config/crd/bases/apps.wandb.com_weightsandbiases.yaml
  • internal/controller/infra/managed/clickhouse/altinity/naming.go
  • internal/controller/infra/managed/clickhouse/altinity/naming_test.go
  • internal/controller/reconciler/clickhouse.go
  • internal/controller/reconciler/clickhouse_replication_test.go
  • internal/crdinstaller/crds/operator/apps.wandb.com_weightsandbiases.yaml

Comment thread api/v2/weightsandbiases_types.go Outdated
type ClickHouseInfraStatus struct {
WBInfraStatus `json:",inline"`
Connection ClickHouseConnection `json:"connection,omitempty"`
Replicated bool `json:"replicated,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- candidate files ---'
git ls-files | rg '(^|/)(weightsandbiases_types\.go|.*clickhouse.*|.*ClickHouse.*|.*crd.*|.*test.*)$' | head -200

printf '%s\n' '--- relevant symbols and field references ---'
rg -n -C 5 \
  'Replicated|managedClickHouseInferStatus|ClickHouseInfraStatus|ClickHouseInfra' \
  api config charts deploy test tests 2>/dev/null | head -500 || true

printf '%s\n' '--- type outline ---'
ast-grep outline api/v2/weightsandbiases_types.go --match 'ClickHouseInfraStatus' --view expanded 2>/dev/null || true

Repository: wandb/operator

Length of output: 18184


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- all status construction and field assignments ---'
rg -n -C 12 \
  'ClickHouseInfraStatus|Replicated\s*[:=]|managedClickHouse|InferStatus|clickhouseStatus' \
  api internal config --glob '*.go' --glob '*.yaml' | head -1000

printf '%s\n' '--- CRD schema occurrences ---'
rg -n -C 10 \
  'replicated|clusterName|clickhouseStatus|ClickHouseInfraStatus' \
  config/crd internal/crdinstaller --glob '*.yaml' --glob '*.go' | head -800

printf '%s\n' '--- likely relevant tests ---'
rg -n -C 15 \
  'Replicated|replicated|ClickHouseInfraStatus|clickhouseStatus' \
  internal/controller api --glob '*_test.go' | head -1000

printf '%s\n' '--- Make targets and working tree ---'
git status --short
rg -n -C 4 '^(lint|test|manifests|generate|sync-crd-embed):|manifests:|generate:|sync-crd-embed:' Makefile makefile **/Makefile 2>/dev/null | head -400 || true

Repository: wandb/operator

Length of output: 50371


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- exact Replicated references ---'
rg -n -C 5 '\bReplicated\b|\breplicated\b' --glob '*.go' --glob '*.yaml' . | head -300

printf '%s\n' '--- ClickHouse reconciler symbols ---'
rg -n '^(func|type) .*ClickHouse|ClickHouse.*Infer|clickHouse.*Infer|managedClickHouse|externalClickHouse' internal/controller/reconciler internal/controller/infra --glob '*.go'

printf '%s\n' '--- ClickHouse reconciler focused source ---'
sed -n '1,260p' internal/controller/reconciler/clickhouse.go

printf '%s\n' '--- CRD clickhouseStatus schema ---'
sed -n '4410,4525p' internal/crdinstaller/crds/operator/apps.wandb.com_weightsandbiases.yaml

printf '%s\n' '--- Make targets ---'
rg -n -C 6 '^(lint|test|manifests|generate|sync-crd-embed):|manifests:|generate:|sync-crd-embed:' Makefile */Makefile 2>/dev/null || true

Repository: wandb/operator

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- managed and external status constructors ---'
sed -n '260,325p' internal/controller/reconciler/clickhouse.go

printf '%s\n' '--- replication tests ---'
sed -n '1,155p' internal/controller/reconciler/clickhouse_replication_test.go

printf '%s\n' '--- CRD schema exact subsection ---'
sed -n '4411,4562p' config/crd/bases/apps.wandb.com_weightsandbiases.yaml

printf '%s\n' '--- generated schema consistency ---'
sha256sum \
  config/crd/bases/apps.wandb.com_weightsandbiases.yaml \
  internal/crdinstaller/crds/operator/apps.wandb.com_weightsandbiases.yaml
cmp -s \
  config/crd/bases/apps.wandb.com_weightsandbiases.yaml \
  internal/crdinstaller/crds/operator/apps.wandb.com_weightsandbiases.yaml \
  && echo 'schema files identical' || echo 'schema files differ'

printf '%s\n' '--- Makefile targets ---'
rg -n -C 8 '^(lint|test|manifests|generate|sync-crd-embed):|manifests:|generate:|sync-crd-embed:' Makefile */Makefile 2>/dev/null || true

printf '%s\n' '--- tool availability ---'
command -v go || true
command -v make || true

Repository: wandb/operator

Length of output: 17814


🏁 Script executed:

#!/bin/bash
set -eu

cat >/tmp/omitempty_probe.go <<'EOF'
package main

import (
	"encoding/json"
	"fmt"
)

type BoolStatus struct {
	Replicated bool `json:"replicated,omitempty"`
}

type PointerStatus struct {
	Replicated *bool `json:"replicated,omitempty"`
}

func main() {
	f := false
	for _, value := range []any{
		BoolStatus{Replicated: false},
		BoolStatus{Replicated: true},
		PointerStatus{Replicated: nil},
		PointerStatus{Replicated: &f},
	} {
		data, err := json.Marshal(value)
		if err != nil {
			panic(err)
		}
		fmt.Println(string(data))
	}
}
EOF

if command -v go >/dev/null 2>&1; then
  go run /tmp/omitempty_probe.go
else
  python3 - <<'PY'
import json
print(json.dumps({}, separators=(",", ":")))
print(json.dumps({"replicated": True}, separators=(",", ":")))
print(json.dumps({}, separators=(",", ":")))
print(json.dumps({"replicated": False}, separators=(",", ":")))
PY
fi

Repository: wandb/operator

Length of output: 199


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- replication defaults and downstream consumers ---'
rg -n -C 8 \
  'replicated|Replicated|defaultValue|ReplicatedMergeTree|clickhouse.*status|clickhouseStatus' \
  pkg internal hack --glob '*.go' --glob '*.yaml' --glob '*.json' | head -800

Repository: wandb/operator

Length of output: 50370


Preserve false for managed single-replica ClickHouse.

bool with omitempty omits the managed false value. Use *bool; set it for managed ClickHouse and leave it nil for external ClickHouse. Regenerate deepcopy and CRD artifacts, and add JSON tests for false, true, and omitted values.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/v2/weightsandbiases_types.go` at line 837, Change Replicated from bool to
*bool so managed single-replica ClickHouse preserves false while external
ClickHouse leaves it nil; update managed ClickHouse construction to set the
pointer and regenerate deepcopy and CRD artifacts. Add JSON coverage verifying
false, true, and omitted values.

@@ -0,0 +1,134 @@
package reconciler

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use a Conventional Commit PR title.

fix/Weave-Clickhouse is not a Conventional Commit title. Rename it, for example, to fix: Weave ClickHouse.

As per coding guidelines, “PR titles and squash commits must use Conventional Commits with an allowed type, and the subject must start with an uppercase letter.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/controller/reconciler/clickhouse_replication_test.go` at line 1,
Rename the pull request title from “fix/Weave-Clickhouse” to a Conventional
Commit format using an allowed type and an uppercase subject, such as “fix:
Weave ClickHouse”.

Source: Coding guidelines

Comment on lines +1 to +13
package reconciler

import (
"context"
"testing"

apiv2 "github.com/wandb/operator/api/v2"
"github.com/wandb/operator/internal/controller/infra/managed/clickhouse/altinity"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use the configured Ginkgo/Gomega test suite.

This new file uses testing.T tests. Move these cases into the existing Ginkgo suite and use Gomega assertions.

As per coding guidelines, “Use Ginkgo/Gomega for tests; test suites are configured through suite_test.go files and envtest.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/controller/reconciler/clickhouse_replication_test.go` around lines 1
- 13, Convert the tests in clickhouse_replication_test.go from testing.T
functions to the existing Ginkgo suite configured by suite_test.go, removing the
direct testing import. Register the cases with Ginkgo and replace testing.T
assertions with Gomega matchers, preserving the existing test behavior and
envtest setup.

Source: Coding guidelines

@collinol collinol changed the title fix/Weave-Clickhouse fix: Weave-Clickhouse Aug 13, 2026
@w-b-hivemind

w-b-hivemind Bot commented Aug 17, 2026

Copy link
Copy Markdown

HiveMind Sessions

1 session · 11m · $2.54

Session Agent Duration Tokens Cost Lines
Watchtower Operator Helm Chart Integration
574fa9ad-396a-48ea-ac1d-4941e9386c08
claude 11m 26.4K $2.54 +453 -5
Total 11m 26.4K $2.54 +453 -5

View all sessions in HiveMind →

Run claude --resume 574fa9ad-396a-48ea-ac1d-4941e9386c08 to pickup where you left off.

// externalClickHouseValues is a minimal v1 external ClickHouse block, so
// conversion has a connection to attach the replication settings to.
func externalClickHouseValues(extra map[string]interface{}) map[string]interface{} {
global := map[string]interface{}{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nit of all nits :), so feel free to ignore for this, but just want to note, we probably at some point want to rewrite all intervace{} to any{} and turn on a linter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants